import React, { useState } from 'react'
import { Row, Col, Radio, InputNumber, Slider, Button, Checkbox, Popover, Switch, Input, Space, Dropdown, Tag, Tooltip } from 'antd'
import SelectCollect from '@/components/SelectCollect'
import { CloseOutlined } from '@ant-design/icons'
import './index.less'
const FormComponents = (props) => {
    const { selectData, data, edit } = props
    const { selectIndex } = data
    const {
        list,
        showMore,
        title,
        titleFlag,
        showCount,
        showComponents,
        countType,
        timeFlag,
        bottom,
        top,
        marginType,
        paddingLeft,
        paddingTop,
    } = selectData
    const handleUpdate = (o) => {
        edit({
            list: data.list.map((val, index) => {
                if (index === selectIndex) {
                    return {
                        ...val,
                        ...o
                    }
                }
                return val
            })
        })
    }
    const [visible, setVisible] = useState(false)
    return <Row gutter={[12, 24]}>
        <Col
            span={24}>
            表单
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            <Space>
                <div>标题栏</div>
                <div style={{ color: '#333333' }}>{titleFlag ? '显示' : '隐藏'}</div>
                <div><Switch onChange={(e) => {
                    handleUpdate({
                        titleFlag: e
                    })
                }} checked={titleFlag}></Switch></div>
            </Space>
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            标题名称
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            <Input
                showCount
                maxLength={20}
                onChange={(e) => {
                    handleUpdate({ title: e.target.value })
                }} value={title}>

            </Input>
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            <Space>
                <div>查看更多</div>
                <div style={{ color: '#333333' }}>{showMore ? '显示' : '隐藏'}</div>
                <div><Switch onChange={(e) => {
                    handleUpdate({
                        showMore: e
                    })
                }} checked={showMore}></Switch></div>
            </Space>
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            当前页显示
            <Radio.Group onChange={(e) => {
                handleUpdate({
                    showComponents: e.target.value
                })
            }} value={showComponents}>
                <Radio value={'all'}>显示全部</Radio>
                <Radio value={'count'}>显示<InputNumber min={1}
                    max={30} onChange={(e) => {
                        handleUpdate({ showCount: e })
                    }} value={showCount}></InputNumber>个</Radio>
            </Radio.Group>
        </Col>
        <Col className='editor-form-setting'
            span={24}>
            表单来源
            {list.map((val, index) => {
                const { title } = val
                return <div key={index} className='imageAd-item'>
                    <Space style={{ width: "100%" }} direction='vertical'>
                        <div>
                            <div>表单</div>
                            <div>{title}</div>
                        </div>
                        <CloseOutlined onClick={(e) => {
                            e.preventDefault();
                            handleUpdate({
                                list: list.filter((item, o) => {
                                    return o !== index
                                })
                            })
                        }} className='close_icon'></CloseOutlined>
                    </Space>
                    <CloseOutlined onClick={(e) => {
                        e.preventDefault();
                        handleUpdate({
                            list: list.filter((item, o) => {
                                return o !== index
                            })
                        })
                    }} className='close_icon'></CloseOutlined>
                </div>
            })}

            <div onClick={() => {
                setVisible({
                    show: true,
                    detail: list
                })
            }} className='imageAd-add-btn'>
                <Button type='link'>+添加表单</Button>
            </div>
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            列表样式
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            <Radio.Group onChange={(e) => {
                handleUpdate({
                    countType: e.target.value
                })
            }} value={countType}>
                <Radio.Button value={'list'}>列表</Radio.Button>
                <Radio.Button value={'bigImage'}>大图</Radio.Button>
                <Radio.Button value={'twoList'}>一行两个</Radio.Button>
            </Radio.Group>
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            <Space>
                <div>已结束的表单</div>
                <div style={{ color: '#333333' }}>{timeFlag ? '显示' : '隐藏'}</div>
                <div><Switch onChange={(e) => {
                    handleUpdate({
                        timeFlag: e
                    })
                }} checked={timeFlag}></Switch></div>
            </Space>
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            组件样式
        </Col>
        <Col
            span={24}>
            <Row gutter={[12, 12]}>
                <Col span={6}>左右内边距</Col>
                <Col span={12}>
                    <Slider
                        min={0}
                        max={32}
                        onChange={(e) => handleUpdate({ paddingLeft: e })}
                        value={paddingLeft}
                    />
                </Col>
                <Col span={6}><InputNumber min={0}
                    max={32} onChange={(e) => {
                        handleUpdate({ paddingLeft: e })
                    }} value={paddingLeft}></InputNumber></Col>
            </Row>
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            外边距：
            <Radio.Group onChange={(e) => {
                handleUpdate({
                    top: 12,
                    bottom: 0,
                    marginType: e.target.value
                })
            }} value={marginType}>
                <Radio value={'detault'}>默认</Radio>
                <Radio value={'customize'}>自定义</Radio>
            </Radio.Group>
        </Col>
        {marginType === 'customize' && <Col
            span={24}>
            <Row gutter={[12, 12]}>
                <Col span={6}>上</Col>
                <Col span={12}>
                    <Slider
                        min={0}
                        max={32}
                        onChange={(e) => handleUpdate({ top: e })}
                        value={top}
                    />
                </Col>
                <Col span={6}><InputNumber min={0}
                    max={32} onChange={(e) => {
                        handleUpdate({ top: e })
                    }} value={top}></InputNumber></Col>
            </Row>
            <Row gutter={[12, 12]}>
                <Col span={6}>下</Col>
                <Col span={12}>
                    <Slider
                        min={0}
                        max={32}
                        onChange={(e) => handleUpdate({ bottom: e })}
                        value={bottom}
                    />
                </Col>
                <Col span={6}><InputNumber min={0}
                    max={32} onChange={(e) => {
                        handleUpdate({ bottom: e })
                    }} value={bottom}></InputNumber></Col>
            </Row>
        </Col>}
        <SelectCollect onSetList={(e, list) => {
            handleUpdate({
                list: list
            })
        }} visible={visible} onClose={() => { setVisible(false) }}></SelectCollect>
    </Row>
}
export default FormComponents